#include "style.h"


drawSumA(TString fin)
{
  SetGlobalStyle(0);
  c1=new TCanvas;
  
  PadSetup(c1);
  c1->SetLeftMargin(0.14);
  c1->SetRightMargin(0.03);

  TFile::Open(fin);

  gr0=XGLUtils::TreeToGraph("mn2d","","xx","aa0");
  gr1=XGLUtils::TreeToGraph("mn2d","","xx","aa1");
  gr2=XGLUtils::TreeToGraph("mn2d","","xx","aa2");
  gr3=XGLUtils::TreeToGraph("mn2d","","xx","aa3");
  //errSumA=XGLUtils::TreeToGraph("mn2d","","xx","errSumA");
  totn=XGLUtils::TreeToGraph("mn2d","","xx","totn");

  for(Int_t ii=0; ii<gr0->GetN(); ii++){
    gr0->GetY()[ii]+=gr1->GetY()[ii]+gr2->GetY()[ii]+gr3->GetY()[ii];
    gr0->GetEYlow()[ii] =TMath::Sqrt(gr0->GetY()[ii]/totn->GetY()[ii]);//errSumA->GetY()[ii];//
    gr0->GetEYhigh()[ii]=TMath::Sqrt(gr0->GetY()[ii]/totn->GetY()[ii]);//errSumA->GetY()[ii];//
  }

  gPad->SetLogx();

  ToNaturalScale(gr0);
  ResetStyle(gr0);
  gr0->GetXaxis()->SetRangeUser(0.6,30);
  gr0->GetYaxis()->SetRangeUser(0.90,1.1);

  gr0->GetXaxis()->SetTitle("p (GeV/c)");
  gr0->GetYaxis()->SetTitle("A_{p}+A_{#pi}+A_{K}+A_{e}");
  gr0->SetMarkerStyle(20);
  gr0->Draw("ap");

  TLatex *tt=new TLatex(3,1.08,fin.Contains("chi2")?"#chi^{2} with regularization on #sum A":"Binned Log-Likelihood");
  tt->Draw();

  TString tag = fin(0,fin.First('.'));
  c1->Print(Form("out%s.eps",tag.Data()));
}
